import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { WechatReplyService } from '../../services/admin/wechat-reply.service';

/**
 * ReplyController
 * 对应 PHP: Reply Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('wechat')
@Controller('adminapi/wechat')
export class ReplyController {
  constructor(private readonly wechatReplyService: WechatReplyService) {}

  /**
   * 关键词回复
   * 路由: GET reply/keywords/:id
   * PHP路由: Route::get('reply/keywords/:id', 'wechat.Reply/keyword')
   */
  @Get('reply/keywords/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async keyword(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: keyword

      return await this.wechatReplyService.getKeywordInfo(id);
    } catch (error) {
      throw new BusinessException('keyword操作失败', error);
    }
  }

  /**
   * getKeywordLists
   * 路由: GET reply/keywords
   * PHP路由: Route::get('reply/keywords', 'wechat.Reply/getKeywordLists')
   */
  @Get('reply/keywords')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: 'getKeywordLists' })
  async getKeywordLists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getKeywordLists

      return await this.wechatReplyService.getKeywordPage();
    } catch (error) {
      throw new BusinessException('getKeywordLists操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: POST reply/keywords
   * PHP路由: Route::post('reply/keywords', 'wechat.Reply/addKeyword')
   */
  @Post('reply/keywords')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async addKeyword(@Body() data: AddKeywordDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: addKeyword

      return await this.wechatReplyService.addKeyword();
    } catch (error) {
      throw new BusinessException('addKeyword操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: PUT reply/keywords/:id
   * PHP路由: Route::put('reply/keywords/:id', 'wechat.Reply/editKeyword')
   */
  @Put('reply/keywords/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async editKeyword(
    @Param('id') id: string,
    @Body() data: EditKeywordDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: editKeyword

      return await this.wechatReplyService.editKeyword(id);
    } catch (error) {
      throw new BusinessException('editKeyword操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: DELETE reply/keywords/:id
   * PHP路由: Route::delete('reply/keywords/:id', 'wechat.Reply/delKeyword')
   */
  @Delete('reply/keywords/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async delKeyword(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: delKeyword

      return await this.wechatReplyService.delKeyword(id);
    } catch (error) {
      throw new BusinessException('delKeyword操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: GET reply/default
   * PHP路由: Route::get('reply/default', 'wechat.Reply/default')
   */
  @Get('reply/default')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async default(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: default

      return await this.wechatReplyService.getDefault();
    } catch (error) {
      throw new BusinessException('default操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: PUT reply/default
   * PHP路由: Route::put('reply/default', 'wechat.Reply/editDefault')
   */
  @Put('reply/default')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async editDefault(@Body() data: EditDefaultDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: editDefault

      return await this.wechatReplyService.editDefault();
    } catch (error) {
      throw new BusinessException('editDefault操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: GET reply/subscribe
   * PHP路由: Route::get('reply/subscribe', 'wechat.Reply/subscribe')
   */
  @Get('reply/subscribe')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async subscribe(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: subscribe

      return await this.wechatReplyService.getSubscribe();
    } catch (error) {
      throw new BusinessException('subscribe操作失败', error);
    }
  }

  /**
   * 关键词回复
   * 路由: PUT reply/subscribe
   * PHP路由: Route::put('reply/subscribe', 'wechat.Reply/editSubscribe')
   */
  @Put('reply/subscribe')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '关键词回复' })
  async editSubscribe(@Body() data: EditSubscribeDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: editSubscribe

      return await this.wechatReplyService.editSubscribe();
    } catch (error) {
      throw new BusinessException('editSubscribe操作失败', error);
    }
  }
}
